<?php
define('ipos',true);
include("./include/config.php");
$category	=	$_GET['c'];
function clean_feed($input) {
	$original = array("<", ">", "&", '"');
	$replaced = array("&lt;", "&gt;", "&amp;", "&quot;");
	$newinput = str_replace($original, $replaced, $input);
	return $newinput;
}

$limit		=	SHOW_RSS;
if($category) {
	$categoryA	=	$db->database("danhmucid,danhmucten","category","danhmucten_kd = '$category'");
	$sql_where	=	"ipos_film.theloai LIKE '%,".$categoryA[0][0].",%'";
}else {
	$sql_where	=	"ipos_film.phimid > 0";
}
$sql_order	=	"ORDER BY ipos_film.phimid DESC";
// tell the browser we want xml output by setting the following header.
header("Content-Type: text/xml; charset=utf-8");
$rss .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
$rss .= "<rss version=\"2.0\">\r\n";
$rss .= "<channel>\r\n";
$rss .= "<title>" . ucwords(NAMEWEB) . " - RSS Feed</title>\r\n";
$rss .= "<link>" . MAIN_URL . "</link>\r\n";
$rss .= "<description>".DECWEB."</description>\r\n";
$rss .= "<language>vi-vn</language>\r\n";
$rss .= "<copyright>Copyright (C) PhimBMT.Vn</copyright>\r\n";
$rss .= "<ttl>60</ttl>\r\n";
$rss .= "<generator>PhimBMT.Vn</generator> \r\n";
$phim		=	$db->database("ipos_film.phimid,ipos_film.tenphim,ipos_film.tentienganh,ipos_film.phimtime,ipos_film_info.phimtxt","film JOIN ipos_film_info ON (ipos_film_info.phimid = ipos_film.phimid)","$sql_where  $sql_order LIMIT $limit");

for($i=0;$i<count($phim);$i++) {
	$m_time = date('D, d M Y H:i:s',$phim[$i][3]);
	$url_phim	=	url_link($phim[$i][1].' - '.$phim[$i][2],$phim[$i][0],'phim');
	$rss .= "<item>\r\n";
	$rss .= "<title>" . clean_feed($phim[$i][1].' - '.$phim[$i][2]) . "</title>\r\n";
	$rss .= "<description>" . clean_feed($phim[$i][4])."</description>\r\n";
	$rss .= "<link>".$url_phim."</link>\r\n";
	$rss .= "<pubDate>".$m_time." GMT</pubDate>\r\n";
	$rss .= "</item>\r\n\r\n";
}

$rss .= "</channel>\r\n";
$rss .= "</rss>\r\n";

echo $rss;
exit();
?>